package com.atguigu.auth.activity;

import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description : TODO
 * @author: lxy
 * @date: 2023/3/22
 * @version: 1.0
 **/
@SpringBootTest
public class ProcessTestDemo1 {

    @Autowired
    private HistoryService historyService;

    @Autowired
    private TaskService taskService;
    //注入RuntimeService
    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private RepositoryService repositoryService;



    @Test
    public void deployProcess01() {
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource("process/jiaban01.bpmn20.xml")
                .name("加班申请流程01")
                .deploy();
        System.out.println(deployment.getId());
        System.out.println(deployment.getName());
    }

    @Test
    public void startProcessInstance01() {
        ProcessInstance processInstance =
                runtimeService.startProcessInstanceByKey("jiaban01");
        System.out.println(processInstance.getProcessInstanceId());
        System.out.println(processInstance.getId());
    }



    ///////////////////////////////////


    ///////////////////////////////////
    //部署流程定义
    @Test
    public void deployProcess() {
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource("process/jiaban.bpmn20.xml")
                .name("加班申请流程")
                .deploy();
        System.out.println(deployment.getId());
        System.out.println(deployment.getName());
    }


    //启动流程实例
    @Test
    public void startProcessInstance() {
        Map<String, Object> variables = new HashMap<>();
        variables.put("assignee1","zhangsan");
        variables.put("assignee2","lisi");
        //创建流程实例,我们需要知道流程定义的key
        ProcessInstance processInstance =
                runtimeService.startProcessInstanceByKey("jiaban", variables);
        //输出实例的相关信息
        System.out.println("流程定义id：" + processInstance.getProcessDefinitionId());
        System.out.println("流程实例id：" + processInstance.getId());
    }
}
